<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
	<script src="/js/libs/jquery-2.1.1.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
	<script src="/js/bootstrap/bootstrap.min.js"></script>
	<script src="/js/bootstrap/bootstrap-select.min.js"></script>
	<script src="/js/jq.js"></script>
	<script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/js/dict.js"></script>
	<script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
	<script src="/js/my/ztree-menu.js"></script>
	<script src="/js/my/permission.js"></script>
	<script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
	<script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class='form-group'>
				<label class='col-md-4 control-label'>借用方人员</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='borrowerPersonnel' id='borrowerPersonnel'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='借用方' type='text'
						   name='borrowerPersonnelName' id='borrowerPersonnelName'
						   readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;"
							class="layui-btn layui-btn-sm"
							onclick="showTableAndFlushFields('user', 'user', '用户', false, false, 'borrowerPersonnel:id', 'borrowerPersonnelName:nickname', 'borrowerDepartment:deptId', 'borrowerDepartmentName:deptName')">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-4 control-label'>借用方部门</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='borrowerDepartment' id='borrowerDepartment'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='借用方部门' type='text'
						   name='borrowerDepartmentName' id='borrowerDepartmentName' readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;"
							class="layui-btn layui-btn-sm"
							onclick="showSpecialTree('borrowerDepartment', 'borrowerDepartmentName', 'dept', '部门', 'root', 'select', 'fasDeptTree', true, true)">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>出借方人员</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='lenderPersonnel' id='lenderPersonnel'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='出借方' type='text'
						   name='lenderPersonnelName' id='lenderPersonnelName'
						   readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;" class="layui-btn layui-btn-sm"
							onclick="showTableAndFlushFields('user', 'user', '用户', true, false, 'lenderPersonnel:id', 'lenderPersonnelName:nickname', 'lenderDepartment:deptId', 'lenderDepartmentName:deptName')">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-4 control-label'>出借方部门</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='lenderDepartment' id='lenderDepartment'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='出借方部门' type='text'
						   name='lenderDepartmentName' id='lenderDepartmentName' readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;"
							class="layui-btn layui-btn-sm"
							onclick="showSpecialTree('lenderDepartment', 'lenderDepartmentName', 'dept', '部门', 'root', 'select','fasDeptTree', true, true)">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>商品</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='goodsId' id='goodsId' >
					<input style="width: 90%;float: left;" class='form-control' placeholder='商品' type='text' name='goodsName' id='goodsName' readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;" class="layui-btn layui-btn-sm"
							onclick="showTableAndFlushFields('fas/goods','goods', '商品', true, false, 'goodsId:id', 'goodsName:name', 'specification:specification', 'goodsUnit:unit')">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>商品规格</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='商品规格' readonly type='text' name='specification' id='specification'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>商品单位</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='商品单位' readonly type='text' name='goodsUnit' id='goodsUnit'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>借用数量</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='借用数量' type='text' name='borrowerNum' id='borrowerNum'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>预计归还时间</label>
				<div class='col-md-8'>
					<input type="text" class="form-control" placeholder="预计归还时间" name = "estimateReturnTime" id="estimateReturnTime">
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>备注</label>
				<div class='col-md-8'>
					<textarea class="form-control" placeholder="备注" name="remark" id="remark"></textarea>
				</div>
			</div>
			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
						<button class="btn btn-primary" type="submit" onclick="save()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>
		</fieldset>
	</form>
</div>
<script type="text/javascript">
    layui.use(['layer','laydate'], function(){
        var layer = layui.layer;
		var layDate = layui.laydate;
		layDate.render({
			elem: '#estimateReturnTime'
            ,done: function(value, date, endDate){
                if ($("#form").data('bootstrapValidator')) {
                    $("#form").data('bootstrapValidator').resetForm();
                }
            }
		});
    });

    // 设置验证规则
    var validatorSettings = {
        message: '验证不通过',
        fields: {
            estimateReturnTime: {
                message: '校验失败',
                validators: {
                    notEmpty: {
                        message: '预计归还时间不能为空'
                    }
                }
            },borrowerNum: {
                message: '校验失败',
                validators: {
                    notEmpty: {
                        message: '借用数量不能为空'
                    }
                }
            },borrowerDepartmentName: {
				message: '校验失败',
				validators: {
					notEmpty: {
						message: '借用方部门不能为空'
					}
				}
			},lenderDepartmentName: {
				message: '校验失败',
				validators: {
					notEmpty: {
						message: '出借方部门不能为空'
					}
				}
			}
        },
        submitHandler: function (validator, form, submitButton) {
            alert("submit");
        }
    };

    $('#form').bootstrapValidator(validatorSettings);

    function save() {
        $('#form').bootstrapValidator(validatorSettings);
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if(!bootstrapValidator.isValid()){
            return;
        }

        var formdata = $("#form").serializeObject();

        $.ajax({
            type : 'post',
            url : '/borrow/',
            contentType: "application/json; charset=utf-8",
            data : JSON.stringify(formdata),
            success : function(json) {
                if (json.code === 0) {
                    layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                        parent.location.reload();//关闭iFrame
                    });
                } else {
                    layer.msg("添加失败：" + json.message, {shift: -1, time: 1000});
                }
            }
        });
    }

</script>
</body>
</html>
